﻿using System;
using System.Collections.Specialized;
using System.Linq;
using iHouse.Common.Const;
using iHouse.Infrastructure;

namespace iHouse.Web.Infrastructure
{
    public class CategorySearchFilter : SearchFilterBase
    {
        protected override void Collect(NameValueCollection contain)
        {
            //Filter with ID condition
            if (contain.AllKeys.Contains(BusinessConst.ID_FIELD))
                this.FilterCollection.Add(BusinessConst.ID_FIELD, Convert.ToInt32(contain[BusinessConst.ID_FIELD]));

            //Filter with Name condition
            if (contain.AllKeys.Contains(BusinessConst.NAME_FIELD))
                this.FilterCollection.Add(BusinessConst.NAME_FIELD, contain[BusinessConst.NAME_FIELD].ToLower());

            //Filter with Type condition
            if (contain.AllKeys.Contains(BusinessConst.TYPE_ID_FIELD) && contain[BusinessConst.TYPE_ID_FIELD] != "0")
                this.FilterCollection.Add(BusinessConst.TYPE_ID_FIELD, Convert.ToInt32(contain[BusinessConst.TYPE_ID_FIELD]));
        }
    }
}